<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>审批新增销售出库</title>
  </head>
  <body>
    <script type="text/javascript">
      Ext.onReady(function(){
        var deliveryOrderId = new Ext.form.Hidden({
          name: 'id',
          value: '<%=params[:id]%>'
        });

        var paymentPropotion = new Ext.form.Hidden({
          name: 'payment_propotion',
          value: '<%=@saleOrderSaleType.payment_propotion%>'
        });

        var paymentPropotion = new Ext.form.NumberField({
          fieldLabel: '系统出货付款比例',
          name: 'payment_propotion',
          readOnly:true,
          allowDecimals: true,
          allowNegative: false,
          anchor: '95%',
          value: '<%=@saleOrderSaleType.payment_propotion%>'
        });

        var saleOrderSubType = new Ext.form.TextField({
          fieldLabel: '销售订单类型',
          name: 'description',
          anchor: '95%',
          readOnly: true,
          value:'<%=@saleOrderSaleType.name%>'
        });
        
        var saleOrderAmount = new Ext.form.NumberField({
          fieldLabel: '销售订单金额',
          readOnly:true,
          allowDecimals: true,
          allowNegative: false,
          anchor: '95%',
          value:'<%=@saleOrderAmount%>'
        });
        
        var receivableAmount = new Ext.form.NumberField({
          fieldLabel: '已收金额',
          readOnly:true,
          allowDecimals: true,
          allowNegative: false,
          anchor: '95%',
          value:'<%=@receivableAmount%>'
        });

        var deliveriedAmount = new Ext.form.NumberField({
          fieldLabel: '已发货金额',
          readOnly:true,
          allowDecimals: true,
          allowNegative: false,
          anchor: '95%',
          value:'<%=@deliveriedAmount%>'
        });

        var currentDeliveryAmount = new Ext.form.NumberField({
          fieldLabel: '本次发货金额',
          readOnly:true,
          allowDecimals: true,
          allowNegative: false,
          anchor: '95%',
          value:'<%=@currentDeliveryAmount%>'
        });

        var balanceAmount = new Ext.form.NumberField({
          fieldLabel: '结余金额',
          readOnly:true,
          allowDecimals: true,
          allowNegative: false,
          anchor: '95%',
          value:'<%=@balanceAmount%>'
        });
        
        var auditingStatus = new Ext.form.RadioGroup({
          //width : 220,
          fieldLabel: '是否通过',
          //hideLabel:true,
          //style:'margin-left:100px;margin-top:20px',
          columns : 2,
          anchor: '90%',
          vertical :false,
          items:[
            {boxLabel:'是',inputValue:'是',name:'auditing_status'},
            {boxLabel:'否',inputValue:'否',name:'auditing_status',checked:true}
          ]
        });

        var auditOpinion = new Ext.form.TextArea({
          fieldLabel: '审批意见',
          name: 'audit_opinion',
          allowBlank: false,
          anchor: '95%',
          height: 80
        });

        //当前付款比例
        var currPP = new Ext.form.NumberField({
          fieldLabel: '当前付款比例',
          readOnly:true,
          allowDecimals: true,
          allowNegative: false,
          anchor: '95%',
          value: receivableAmount.getValue()/saleOrderAmount.getValue()
        });
        
        //提交按钮
        var deliveryOrderAuditButton = new Ext.Button({
          text: '提交',
          iconCls: 'icon-save',
          handler: function(){
            deliveryOrderAuditButton.setDisabled(true);
            //判断一下，只有工程类的在金额不齐的情况下才可以提交。个人的不可以提交            
            if(currPP.getValue() < paymentPropotion.getValue() && auditingStatus.getValue().getRawValue() == '是'){
              deliveryOrderAuditButton.setDisabled(false);
              Ext.Msg.alert('提示信息','出库金额付款比例，不能小于设定比例！');
              return;
            }
            
            if (deliveryOrderAuditFormPanel.form.isValid()) {
              deliveryOrderAuditFormPanel.form.submit({
                success: function(result, resp){
                  if (resp.result.info.indexOf("成功") >= 0) {
                    deliveryOrderAuditForAddWin.destroy();
                  } else {
                    Ext.MessageBox.show({
                      title: '消息',
                      msg: resp.result.info,
                      buttons: Ext.MessageBox.OK,
                      icon: Ext.MessageBox.WARNING
                    });                    
                  }
                  deliveryOrderAuditButton.enable();
                },
                failure: function(result, request){
                  deliveryOrderAuditButton.enable();
                  Ext.MessageBox.show({
                    title: '消息',
                    msg: "通讯失败，请从新操作",
                    buttons: Ext.MessageBox.OK,
                    icon: Ext.MessageBox.WARNING
                  });
                }
              });
            }
            else {
              deliveryOrderAuditButton.enable();
            }
          }
        })
        
        var deliveryOrderAuditFormPanel = new Ext.form.FormPanel({
          labelWidth: 100,
          width: '380',
          labelAlign: 'right',
          frame : true,
          url: '/delivery_order/updateAuditingStatus',
          method: 'GET',
          items: [{
              layout: 'column',
              border: false,
              items: [{
                  columnWidth: .5,
                  layout: 'form',
                  border: false,
                  items: [saleOrderSubType]
                },{
                  columnWidth: .5,
                  layout: 'form',
                  border: false,
                  items: [saleOrderAmount]
                }]
            },{
              layout: 'column',
              border: false,
              items: [{
                  columnWidth: .5,
                  layout: 'form',
                  border: false,
                  items: [receivableAmount]
                },{
                  columnWidth: .5,
                  layout: 'form',
                  border: false,
                  items: [deliveriedAmount]
                }]
            },{
              layout: 'column',
              border: false,
              items: [{
                  columnWidth: .5,
                  layout: 'form',
                  border: false,
                  items: [currentDeliveryAmount]
                },{
                  columnWidth: .5,
                  layout: 'form',
                  border: false,
                  items: [balanceAmount]
                }]
            },{
              layout: 'column',
              border: false,
              items: [{
                  columnWidth: .5,
                  layout: 'form',
                  border: false,
                  items: [currPP]
                },{
                  columnWidth: .5,
                  layout: 'form',
                  border: false,
                  items: [paymentPropotion]
                }]
            },auditingStatus,deliveryOrderId,auditOpinion],
          buttons: [deliveryOrderAuditButton,{
              text: '关闭',
              iconCls: 'exit',
              handler: function(){
                deliveryOrderAuditForAddWin.destroy();
              }
            }]
        });
        deliveryOrderAuditFormPanel.render('audit_delivery_order_form');
      })
    </script>
    <div id="audit_delivery_order_form"></div>
  </body>
</html>
